<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./react_dom/react/react17.development.js"></script>
    <script src="./react_dom/react/react-dom17.development.js"></script>
    <script src="./react_dom/react/babel.min.js"></script>
</head>

<body>
    <div id="main"></div>
    <script type="text/babel">
        // 对fetch进行封装 
        async function ajax(url) {
            return fetch(url, { method: 'get'})
                .then((data) => data.json())
                .then((res) => res);// 发送请求得到的res
        }
        class Com extends React.Component {
            render() {
                console.log('render被调用了')
                return (<div></div>)

            }
            // componentDidMount() 声明周期函数的一个
            // 渲染dom时执行的函数
            // 组件加载时直接执行的代码，放在这个函数内
            async componentDidMount() {
                console.log('componentDidMount别调用了')
                let res = await ajax('https://cnodejs.org/api/v1/topics')
                console.log(res);
                
            }


        }
        ReactDOM.render(<Com />, document.getElementById("main"))

    </script>
</body>

</html>